<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>杰哥的登录</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h1 style="text-align:center">杰哥的登录</h1>
<div class="text-center">
    <form class="form-inline" action="zxj/login2.php" method="post">
        用户名：<input style="margin-right: 13px;" type="text" id='username' name="username" class="form-control"><br/><br/>
        密码：<input type="password" id='password' name="password" class="form-control"><br/><br/>
        <input type="button" id='btn' value="登录" class="btn btn-primary">
    </form>
</div>

<script src="https://code.jquery.com/jquery.js"></script>
<script src="https://cdn.bootcss.com/layer/3.1.0/layer.js"></script>
</body>
</html>
<script type="text/javascript">
    $('#btn').click(function () {

        if ($('#username').val() == '') {
            layer.msg('用户名不能为空');
            return false;
        }

        if ($('#password').val() == '') {
            layer.msg('密码不能为空');
            return false;
        }

        $.ajax({
            type: 'post',
            url: 'zxj/login2.php',
            data: {
                username: $('#username').val(),
                password: $('#password').val()
            },
            dataType: 'json',
            success: function (res) {
                if (res.status == 1) {
                    layer.msg(res.msg, {icon: 6});
                    setTimeout("window.location.href='/zxj/index2.php'", 2000);
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            }

        });


    });
</script>